package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-06-15
 * Time: 20:39
 */
/*
* 学习内部类
* */
public class Restaurant {
    private String name;
    private String address;

    public void test(){
        //通过外部方法，访问内部类
        MenuItem menuItem = new MenuItem("辣椒炒肉",12);
        String foodName = menuItem.getFoodName();
        double price = menuItem.getPrice();
        System.out.println(foodName + price + "元");
    }
    /*
    如果内部类被private修饰
    迂回战术，我们就在外部类中创建一个方法去创建内部类对象
    */

    public void createMenuItem(String foodName , double price){
        MenuItem menuItem = new MenuItem(foodName,price);
    }

    /*
    * 局部内部类，实际场景中用的很少*/

    public void showSpicy(String spicy){
        class Spicy{
            public void display(){
                System.out.println("辣度是" + spicy);
            }
        }
        Spicy s = new Spicy();
        s.display();
    }

    private  class MenuItem{
        private String foodName;
        private double price;

        public MenuItem(String foodName , double price){
            this.foodName = foodName;
            this.price = price;
        }


        public String getFoodName(){
            return foodName;
        }

        public double getPrice(){
            return price;
        }
    }


}
